package com.hengtiansoft.lfy.chart.net;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @ClassName: NetWorkUtil
 * @Description: 上传图片，使用volley上传图片大于3K会出现上传失败的情况
 * @author caijiajun
 * @date 2015年12月14日 下午3:57:57
 * 
 */
public class NetWorkUtil {

    public static String httpPost(String url, List<NameValuePair> params) {
        String result = "";
        HttpPost httpRequest = new HttpPost(url);
        try {
            httpRequest.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse httpResponse = new DefaultHttpClient()
                    .execute(httpRequest);
            result = EntityUtils.toString(httpResponse.getEntity());
        } catch (UnsupportedEncodingException e) {
            result = "服务器有误";
        } catch (ClientProtocolException e) {
            result = "服务器有误";
        } catch (IOException e) {
            result = "服务器有误";
        }
        return result;
    }

}
